package com.jqq.string_;

/**
 * @author 姬倩倩
 * @version 1.0
 */
public class StringMethod01 {
    public static void main(String[] args) {
        //equals
        String str1 = "hello";
        String str2 = "HELLO";
        System.out.println(str1.equals(str2));
        //equalsIgnoreCase
        String username = "john";
        String username1 = "JOHN";
        System.out.println(username.equalsIgnoreCase(username1));
        //length
        System.out.println("姬倩倩".length());
        //indexOf
        String s1 = "abc@defabc";
        int index = s1.indexOf("@");
        System.out.println(index);
        int index2 = s1.indexOf("def");
        System.out.println(index2);
        //lastIndexOf
        index = s1.lastIndexOf('a');
        System.out.println(index);
        //subString
        System.out.println(s1.substring(1));
        System.out.println(s1.substring(1,3));
        //toUpperCase
        String s2 = s1.toUpperCase();
        System.out.println(s2);
        //toLowerCase
        System.out.println(s2.toLowerCase());
        //concat
        String s3 = s1.concat(s2);
        System.out.println(s3);
        //replace
        String s4 = s3.replace("abc","666");
        System.out.println(s4);
        //split 按特定元素切分字符串 返回一个数组
        //如果特殊字符 需要加入转义符 \
        String s5 = "小 猫 真 可 爱 ";
        String[] strs = s5.split(" ");
        for(String str : strs){
            System.out.print(str);
        }
        System.out.println();
        String address = "上海\\奉贤\\海湾";
        String[] ads = address.split("\\|");//上海\奉贤\海湾
        ads = address.split("\\\\");//上海奉贤海湾
        for(String str : ads){
            System.out.print(str);
        }
        System.out.println();
        s1 = "happy";
        char[] chars = s1.toCharArray();
        for(char c : chars){
            System.out.print(c+" ");
        }
        System.out.println();
        //compareTo
        String a = "john";
        String b = "jack";
        System.out.println(a.compareTo(b));
        //format
        String name = "john";
        int age = 22;
        double score = 96.497;
        String s  = "name = %s,age = %d,score = %.2f";
        String info = String.format(s, name,age,score);
        System.out.println("info: "+info);
        /*
        public PrintStream printf(String format, Object ... args) {
            return format(format, args);
        }
         */
        System.out.printf("name = %s,age = %d,score = %.2f%n",name,age,score);
    }
}
